package com.heima.wemedia.controller.v1;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.AdChannel;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @GetMapping("channels")
    public ResponseResult findAll(){
        return wmChannelService.findAll();
    }

    /**
     * 频道列表展示
     * @param channelDto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody ChannelDto channelDto){
        return wmChannelService.getList(channelDto);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        return wmChannelService.removeChannelById(id);
    }

    /**
     * 新增
     * @param wmChannel
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        wmChannelService.save(wmChannel);
        return ResponseResult.okResult("");
    }

    /**
     * 修改
     * @param adChannel
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return wmChannelService.updateChannel(adChannel);
    }


}
